using DG.Tweening;
using DG.Tweening.Core;
using Sirenix.OdinInspector;
using UnityEngine;
using Utils.UGUI;

namespace WorkFlow.TweenGo
{
    [ExecuteAlways]
    public class UIRoundRectangleTween : TweenGoBase<UIRoundRectangle,float>
    {
        public Vector4 startVector4;
        public Vector4 endVector4;

        [Range(0,1f)] 
        #if UNITY_EDITOR
        [OnValueChanged("SetRadius")] 
        #endif
        public float currentValue = 0f;

        protected override Tweener CreateTween(DOGetter<float> startValueGetter, DOSetter<float> setter, float endValue, float duration)
        {
            return DOTween.To(startValueGetter, setter, endValue, duration);
        }

        protected override void SetValue(float value)
        {
            currentValue = value;
            SetRadius();
        }

        protected override float CurrentValue()
        {
            return currentValue;
        }

        private void SetRadius()
        {
            var tempV4 = Vector4.Lerp(startVector4, endVector4, currentValue);
            Target.RoundTopRadius = new Vector2(tempV4.x, tempV4.y);
            Target.RoundBottomRadius = new Vector2(tempV4.z, tempV4.w);
        }
    }
}
